package pri.zxx.excelgenerate.dataentity.tabledata.predict;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.stereotype.Component;
import pri.zxx.excelgenerate.dataentity.entity.*;
import pri.zxx.excelgenerate.dataentity.tabledata.MultiTitleModuleCreatorTemplate;
import pri.zxx.excelgenerate.dataentity.tabledata.TableDefinition;

import java.util.ArrayList;
import java.util.List;

/**
 * 妊娠母猪
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@Component
public class PredictModuleCreator extends MultiTitleModuleCreatorTemplate {

    //todo 注入数据获取的bean

    @Override
    public List<ModuleMetaInfo> creator(CreatRequest creatRequest) {
        List<ModuleMetaInfo> modules = new ArrayList<>();
        List<CreatRequest.Range> ranges = creatRequest.getRanges();
        //todo 有范围要求的表格 根据选择的范围拆分 向上取整
        //组装元数据 todo 有些表格需要填充范围信息作为表头
        ModuleMetaInfo metaInfo = new ModuleMetaInfo();
        metaInfo.setModuleTitle(moduleInfo().getName()).setModuleInfoEnum(moduleInfo());


        TableDefinition tableDefinition = new TableDefinition();

        tableDefinition = dataHandle(moduleMetaInfoHandle(tableDefinition, creatRequest), creatRequest);
        //根据不同类型动物 组装数据
        creatRequest.setRanges(ranges);
        metaInfo.setTableDefinition(tableDefinition);
        modules.add(metaInfo);
        return modules;
    }

    @Override
    public ModuleInfoEnum moduleInfo() {
        return ModuleInfoEnum.PREDICTION;
    }

    @Override
    public TableDefinition moduleMetaInfoHandle(TableDefinition tableDefinition, CreatRequest creatRequest) {

        return tableDefinition;
    }

    @Override
    public TableDefinition dataHandle(TableDefinition tableDefinition, CreatRequest creatRequest) {
        ExcelData excelData;
        //todo 通过已有接口 根据不同类型 组装表格数据
        switch (creatRequest.getPredictionTypeEnum()) {
            case GESTATING_SOWS:
                excelData = new GestatingSowsPredictionInfo();
                break;
            case STARTING_PIGS:
                excelData = new StartingPigsPredictionInfo();
                break;
            case LACTATING_SOWS:
                excelData = new LactaingSnowsPredictionInfo();
                break;
            case GROWING_FINISHING:
                excelData = new GrowingFinishingPredictionInfo();
                break;
            default:
                throw new RuntimeException("动物类型异常");
        }
        tableDefinition = loadObjectData(tableDefinition, creatRequest, excelData, true);
        return tableDefinition;
    }

    @Override
    public Class<? extends ExcelData> getByType(PredictionTypeEnum predictionTypeEnum) {
        switch (predictionTypeEnum) {
            case GESTATING_SOWS:
                return GestatingSowsPredictionInfo.class;
            case STARTING_PIGS:
                return StartingPigsPredictionInfo.class;
            case LACTATING_SOWS:
                return LactaingSnowsPredictionInfo.class;
            case GROWING_FINISHING:
                return GrowingFinishingPredictionInfo.class;
            default:
                throw new RuntimeException("动物类型异常");
        }
    }
}
